package com.example.lanouhn.bantangapp.activities.activities;

import android.app.Activity;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import com.example.lanouhn.bantangapp.R;
import com.example.lanouhn.bantangapp.activities.adapters.VpSelectedAdapter;
import com.example.lanouhn.bantangapp.activities.fragments.Fragment_CommnityAraticalDynAra;
import com.example.lanouhn.bantangapp.activities.fragments.Fragment_CommnityAraticalDynsun;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by lanouhn on 16/7/23.
 * 关注动态
 */
public class CommunityArticalDynamic extends FragmentActivity {
    private ImageView back;
    private ViewPager vp;
    private TabLayout tab;
    private List<String> tabNames;
    //viewPager的适配器
    private VpSelectedAdapter vpfAdapter;
    private List<Fragment> fragments;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initview();
        initLinstener();
        initData();
        setDataToView();//绑定数据到视图
    }
    //找到控件
    private void initview() {
        setContentView(R.layout.community_article_dynamic_activity);
        back= (ImageView) findViewById(R.id.back);
        vp= (ViewPager) findViewById(R.id.vp);
        tab= (TabLayout) findViewById(R.id.tab);
    }

    //数据集合
    private void initData() {
        //tablayout集合
        tabNames = new ArrayList<>();
        tabNames.add(getResources().getString(R.string.avatar_j));
        tabNames.add(getResources().getString(R.string.avatar_k));
        //Fragment集合
        fragments = new ArrayList();
        // 添加页面
        fragments.add(new Fragment_CommnityAraticalDynAra());
        fragments.add(new Fragment_CommnityAraticalDynsun());

    }
    //绑定数据
    private void setDataToView() {
        vpfAdapter = new VpSelectedAdapter(getSupportFragmentManager(), tabNames, fragments);
        //设置适配器
        vp.setAdapter(vpfAdapter);
        //tabLayout和ViewPager绑定
        tab.setupWithViewPager(vp);
    }
        //点击监听

    private void initLinstener() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
}
